/*
 * Gameplay - Control screens for gameplay
 *
 * Copyright 2007 James W. Hofmann
 *
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

class Gameplay
{
	
	public static var wallplacebutton : Control;
	public static var towerplacebutton : Control;
	public static var undobutton : Control;
	public static var startbutton : Control;
	public static var resetbutton : Control;
	public static var uppow : Control;
	public static var upspd : Control;
	public static var uprng : Control;

	public static var placetype : Int;
	public static var upgradetype : Int;
	public static var placearr : Array<Control>;
	public static var uparr : Array<Control>;
	
	public static function initgraphics()
	{
		// tilebg, hud overlays
		// and new buttons
		
		var controls = StandardControls.listTextButton(
		["Wall","Tower","*",
		"+Power","+Speed","+Range"],
		"Vera Bold", 18,
		0xDDDDDD,
		0x666688, 0.75,
		0xBBBBDD, 0.75,
		0xFFFFFF, 0.75,
		2, 2, 3, 110);

		var controlsright = StandardControls.listTextButton(
		[
		"Start!","*",
		"Undo","*",
		"Quit"],
		"Vera Bold", 18,
		0xDDDDDD,
		0x666688, 0.75,
		0xBBBBDD, 0.75,
		0xFFFFFF, 0.75,
		680-110-2, 2, 3, 110);
		
		wallplacebutton = controls[0];
		towerplacebutton = controls[1];

		uppow = controls[3];
		upspd = controls[4];
		uprng = controls[5];

		placearr = [wallplacebutton,towerplacebutton];
		uparr = [uppow,upspd,uprng];

		wallplacebutton.onClick = function() 
		{	
			setmany(0,placearr); 
			placetype=0; 
			screenPlacement();
		}
		towerplacebutton.onClick = function() 
		{
			setmany(1,placearr); 
			placetype=1;
			screenPlacement();
		}

		uppow.onClick = function() {setmany(0,uparr); upgradetype=0;}
		upspd.onClick = function() {setmany(1,uparr); upgradetype=1;}
		uprng.onClick = function() {setmany(2,uparr); upgradetype=2;}
		
		setmany(0,placearr);
		setmany(0,uparr);
		
		undobutton = controlsright[2];
		startbutton = controlsright[0];
		resetbutton = controlsright[4];
		
		startbutton.onClick = function()
		{
			Game.cur.phase = 3;
		}

	}
	
	public static function setmany(num : Int, arr : Dynamic)
	{

		for (n in 0...arr.length)
		{
			var spr = arr[n].sprite;
			if (n==num)
			{
				arr[n].onFrame=function()
				{
					spr.graphics.clear();
					spr.graphics.lineStyle(2,0xFFFFFF, 0.75);
					spr.graphics.beginFill(0x886666, 0.75);
					spr.graphics.drawRoundRect(0,0,arr[n].width,arr[n].height,16,16);					
				};
				arr[n].onMouseOver=function()
				{
					spr.graphics.clear();
					spr.graphics.lineStyle(2,0xFFFFFF, 0.75);
					spr.graphics.beginFill(0xDDBBBB, 0.75);
					spr.graphics.drawRoundRect(0,0,arr[n].width,arr[n].height,16,16);					
				};
			}
			else
			{
				arr[n].onFrame=function()
				{
					spr.graphics.clear();
					spr.graphics.lineStyle(2,0xFFFFFF, 0.75);
					spr.graphics.beginFill(0x666688, 0.75);
					spr.graphics.drawRoundRect(0,0,arr[n].width,arr[n].height,16,16);				
				};
				arr[n].onMouseOver=function()
				{
					spr.graphics.clear();
					spr.graphics.lineStyle(2,0xFFFFFF, 0.75);
					spr.graphics.beginFill(0xBBBBDD, 0.75);
					spr.graphics.drawRoundRect(0,0,arr[n].width,arr[n].height,16,16);					
				};
			}	
		}		
	}
	
	public static function screenPlacement()
	{
		Control.reset();
		
		wallplacebutton.show();
		towerplacebutton.show();
		if (placetype==1)
		{
			uppow.show();
			upspd.show();
			uprng.show();
		}
		undobutton.show();
		startbutton.show();
		resetbutton.show();
	}
	
	public static function screenFight()
	{
		Control.reset();
	}
	
}
